<?php
/*
 * @Author: 李明
 * @Date: 2021-11-08 16:08:05
 * @LastEditTime: 2022-01-05 19:42:46
 * @LastEditors: 李明
 * @Description: 小程序订单接口
 * @FilePath: /CRM2.0-PHP/app/Http/Resources/OrderXcx.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Resources;

use App\Http\Controllers\Utils;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderXcx extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $order['id'] = $this->id;
        $order['valid_time'] = date('Y-m-d', strtotime($this->valid_time));
        $order['sign_time'] = date('Y-m-d', strtotime($this->sign_time));
        $order['account_time'] = date('Y-m-d', strtotime($this->account_time));
        $order['contract_end_date'] =  date('Y-m-d', strtotime($this->contract_end_date));
        $order['order_money'] = Utils::moneyDeal($this->order_money);
        $order['order_status'] = $this->order_status;
        $order['contract_no'] = $this->contract_no;
        $order['product_name'] = $this->product->name;
        $order['order_status_str'] = $this->orderStatusToStr($this->order_status);;
        return $order;
    }
    public static function orderStatusToStr($order_status)
    {
        switch ($order_status) { // 订单状态 -1草稿， 1是待付款  2是审核中   3是待生效(弃用)  4是已生效 5是拒绝  6是已结束    ,7废弃8提前终止
            case '-1':
                $order_status = '草稿';
                break;
            case '1':
                $order_status = '待付款';
                break;
            case '2':
                $order_status = '审核中';
                break;
            case '3':
                $order_status = '待生效';
                break;
            case '4':
                $order_status = '生效中';
                break;
            case '5':
                $order_status = '拒绝';
                break;
            case '6':
                $order_status = '已完结';
                break;
            case '7':
                $order_status = '已废弃';
                break;
            case '8':
                $order_status = '提前终止';
                break;
            default:
                $order_status = '未知';
                break;
        }
        return $order_status;
    }
}
